package com.java.control.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;

import com.java.common.SessionInfo;
import com.java.control.AbstractAdminCommandController;
import com.java.control.search.CodeSearchCond;
import com.java.control.search.SendSearchCond;
import com.java.control.search.SearchStat;
import com.java.control.search.UserSearchCond;
import com.java.entity.Code;
import com.java.entity.SendExpress;
import com.java.entity.User;
import com.java.mis.UserType;
import com.java.service.CodeService;
import com.java.service.SendService;
import com.java.service.UserService;

/**
 * 样品管理
 * @author wqf
 * @version  Nov 24, 2011 12:00:53 PM
 */
public class SendListController extends AbstractAdminCommandController {

	public SendListController(){
		this.setCommandClass(SendSearchCond.class);
	}	

	protected ModelAndView executeRequest(HttpServletRequest request,HttpServletResponse response,Object command)
		throws Exception{
		
		SendSearchCond searchCond = (SendSearchCond)command;
		
		ModelAndView mav=new ModelAndView(this.view);
		searchCond.setPageSize(10L);
				
		SessionInfo user = getSessionInfo(request);
		if(null!=user){
			if(user.getUserType()==UserType.admin){
				
			}else{
				searchCond.setUserId(user.getUserId());
			}
		}
		
		SearchStat searchStat = this.sendService.getSearchStat(SendExpress.class, searchCond);
		List<SendExpress> list = this.sendService.search(SendExpress.class,searchCond,"id desc");
		mav.addObject("searchStat", searchStat);
		mav.addObject("searchCond", searchCond);
		mav.addObject("sendList", list);				
		
		//用户信息
		UserSearchCond userSearchCond = new UserSearchCond();
		SessionInfo sessionInfo = this.getSessionInfo(request);
		if(null!=sessionInfo){
			if(sessionInfo.getUserType()!=UserType.admin){
				userSearchCond.setUserId(sessionInfo.getUserId());
			}
		}
//		userSearchCond.setIsAdmin(false);//允许管理员添加
		userSearchCond.setStatus(true);
		List<User> userList = this.userService.search(User.class,userSearchCond);
		mav.addObject("userList", userList);
		
		//快递公司
		CodeSearchCond codeSearchCond = new CodeSearchCond();
		codeSearchCond.setCodeType("快递公司");
		List<Code> expressList = this.codeService.search(Code.class,codeSearchCond);
		mav.addObject("companyList", expressList);
		
		//国家
		CodeSearchCond countrySearchCond = new CodeSearchCond();
		countrySearchCond.setCodeType("国家");
		List<Code> countryList = this.codeService.search(Code.class,countrySearchCond);
		mav.addObject("countryList", countryList);
		
		return mav;
		
	}
		
	private String view;
	private SendService sendService;
	private UserService userService;
	private CodeService codeService;

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public void setCodeService(CodeService codeService) {
		this.codeService = codeService;
	}

	public void setSendService(SendService sendService) {
		this.sendService = sendService;
	}

	public void setView(String view) {
		this.view = view;
	}

}
